<?php

namespace App\Services\MiniprogramToGame\HotSearch;

use App\Services\ServiceBase;
use App\Structs\HotSearchStruct;
use Illuminate\Support\Facades\Http;

/**
 * sogou热搜
 * 网页地址 https://ie.sogou.com/top/
 */
class Sogou extends ServiceBase
{
    public function reptile()
    {
        $url = 'https://go.ie.sogou.com/hot_ranks';
        $response = Http::withHeaders([
            'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36',
        ])->get($url);
        if (!$response->ok()) {
            return false;
        }

        $data = json_decode($response->body(), true);

        $list = [];
        foreach ($data['data'] as $index => $item) {
            $class           = new HotSearchStruct;
            $class->title    = $item['attributes']['title'];
            $class->desc     = $item['attributes']['title'];
            $class->hotIndex = $item['attributes']['rank'];
            $class->hotValue = $item['attributes']['num'];
            $class->url      = "https://www.sogou.com/sie?query={$class->title}&ie=utf8#enc";
            $list[] = $class;
        }

        return $list;
    }
}
